package com.cn.label.service;

import com.cn.api.LabelService;
import com.cn.dto.LabelDto;
import com.cn.label.mapper.LabelDao;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Service
@Component("LabelService")
@RestController
@RequestMapping("/label")
public class LabelServiceImpl implements LabelService {
    @Autowired
    private LabelDao labelDao;
    @Override
    @PostMapping("update")
    public int update(LabelDto labelDto) {
        int update = labelDao.update(labelDto);
        return update;
    }

    @Override
    @PostMapping("insert")
    public int insert(LabelDto labelDto) {
        int insert = labelDao.insert(labelDto);
        return insert;
    }

    @Override
    @GetMapping("findById")
    public LabelDto findById(int id) {
        LabelDto byId = labelDao.findById(id);
        return byId;
    }

    @Override
    @GetMapping("delete")
    public int delete(int id) {
        int delete = labelDao.delete(id);
        return delete;
    }

    @Override
    public List<LabelDto> findAll(int limit, int page) {
        PageHelper.startPage(limit,page);
        List<LabelDto> all = labelDao.findAll();
        return all;
    }



}
